package com.zhiliao.decorator.demo2;

import com.zhiliao.decorator.beans.MessageContent;
import com.zhiliao.decorator.beans.OrderContent;

public abstract class AbstractMessageDecorator<C> implements Message{

    private Message message;

    public AbstractMessageDecorator(Message message) {
        this.message = message;
    }

    @Override
    public void getMessage(String content) {
        message.getMessage(content);
        handlerMessage(content);
    }

    protected void handlerMessage(String content) {
        MessageContent<C> messageContent = deserializeMessage(content);
        boolean preCheckMessage = preCheckMessage(messageContent);
        if (!preCheckMessage) {
            return;
        }
        service(messageContent);
    }

    //消息反序列化
    protected abstract MessageContent deserializeMessage(String content);

    //消息预校验
    protected abstract boolean preCheckMessage(MessageContent<C> messageContent);

    //消息前置补偿

    //业务操作
    protected abstract void service(MessageContent<C> messageContent);

    //后置补偿
}
